# SPAM3-UK Makefile

.PHONY: build run clean test init-db sample-data api-test

# 构建应用
build:
	go build -o spam3uk main.go

# 运行应用
run: build
	./spam3uk

# 清理构建文件
clean:
	rm -f spam3uk

# 运行测试
test:
	go test -v ./...

# 初始化数据库
init-db:
	mysql -u root -p123 -h localhost dcp-cloud < db_scripts/create_table.sql

# 插入示例数据
sample-data:
	mysql -u root -p123 -h localhost dcp-cloud < db_scripts/sample_data.sql

# 测试API
api-test:
	@echo "测试健康检查..."
	@curl -s http://localhost:8080/health | jq .
	@echo -e "\n测试Ford分类统计..."
	@curl -s "http://localhost:8080/api/categories" | jq '.stats'
	@echo -e "\n测试Performance分类车辆..."
	@curl -s "http://localhost:8080/api/categories/performance/vehicles" | jq '.total'
	@echo -e "\n测试混合动力分类车辆..."
	@curl -s "http://localhost:8080/api/categories/hybrid_electric/vehicles" | jq '.data[] | {model, fuel_type}' | head -6

# 下载依赖
deps:
	go mod download
	go mod tidy

# 开发模式运行
dev: deps sample-data
	go run main.go

# 完整设置（首次运行）
setup: deps init-db sample-data build
	@echo "设置完成！运行 'make run' 启动服务"

# 显示帮助
help:
	@echo "SPAM3-UK Ford汽车信息抓取系统"
	@echo ""
	@echo "可用命令:"
	@echo "  build       - 构建应用程序"
	@echo "  run         - 构建并运行应用程序"
	@echo "  clean       - 清理构建文件"
	@echo "  test        - 运行测试"
	@echo "  init-db     - 初始化数据库表结构"
	@echo "  sample-data - 插入示例数据"
	@echo "  api-test    - 测试API接口"
	@echo "  deps        - 下载和整理依赖"
	@echo "  dev         - 开发模式运行"
	@echo "  setup       - 首次完整设置"
	@echo "  help        - 显示此帮助信息"
